package com.eeepay.eeepay_v2.adapter;

import android.content.Context;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.util.SpanUtils;
import com.eeepay.v2_library.adapter.ABBaseAdapter;
import com.eeepay.v2_library.adapter.ABViewHolder;

import cn.eeepay.api.grpc.nano.MerchantSearchProto;

/**
 * Created by Administrator on 2016/3/4 0004.
 */
public class IntoQueryAdapter extends ABBaseAdapter<MerchantSearchProto.MerchantInfoSear> {

    public IntoQueryAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_into_query_list;
    }

    @Override
    public void convert(ABViewHolder holder, MerchantSearchProto.MerchantInfoSear model) {
        holder.setText(R.id.tv_number, model.merchantNo);
        holder.setText(R.id.tv_name, model.merchantName);
        holder.setText(R.id.tv_phone, model.mobilephone);

        //根据状态码显示相应的状态
        int status = 0;
        int color = 0;
        switch (Integer.parseInt(model.status)) {
            case 1:
                status = R.string.status_1;
                color = R.color.btn_red;
                break;
            case 2:
                status = R.string.status_2;
                color = R.color.btn_red;
                break;
            case 3:
                status = R.string.status_3;
                color = R.color.btn_red;
                break;
            case 4:
                status = R.string.status_4;
                color = R.color.unify_txt_color_black;
                break;
        }
//        SpannableString ss = new SpannableString(status);
//        ss.setSpan(new ForegroundColorSpan(MyApplication.context.getResources().getColor(color)),
//                0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (status != 0 && color != 0)
            holder.setText(R.id.tv_state, SpanUtils.getSpan(mContext.getResources().getString(status), color));
        holder.setText(R.id.tv_product, model.bpName);
        holder.setText(R.id.tv_create_time, model.createTime);
//        holder.setText(R.id.tv_opinion, model.examinationOpinions);
        holder.setTextAndColor(R.id.tv_opinion, model.examinationOpinions,color);
    }

//    @Override
//    public void convert(ABViewHolder holder, IntoQueryInfo model) {
//        holder.setText(R.id.tv_number, model.getMerNo());
//        holder.setText(R.id.tv_name, model.getName());
//        holder.setText(R.id.tv_phone, model.getPhone());
//
//        //根据状态码显示相应的状态
//        int status = 0;
//        int color = 0;
//        switch (Integer.parseInt(model.getState())) {
//            case 1:
//                status = R.string.status_1;
//                color = R.color.btn_blue;
//                break;
//            case 2:
//                status = R.string.status_2;
//                color = R.color.btn_green;
//                break;
//            case 3:
//                status = R.string.status_3;
//                color = R.color.btn_red;
//                break;
//            case 4:
//                status = R.string.status_4;
//                color = R.color.btn_red;
//                break;
//        }
////        SpannableString ss = new SpannableString(status);
////        ss.setSpan(new ForegroundColorSpan(MyApplication.context.getResources().getColor(color)),
////                0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//        if (status != 0 && color != 0)
//            holder.setText(R.id.tv_state, SpanUtils.getSpan(mContext.getResources().getString(status), color));
//        holder.setText(R.id.tv_product, model.getProduct());
//        holder.setText(R.id.tv_create_time, model.getCreateTime());
//        holder.setText(R.id.tv_opinion, model.getOpinion());
//    }
}
